/**
 * 0：未提交
 * 1：审核中
 * 2：已审核
 * 3：审核失败
 */

export const columnsMap = [
  {
    label: 'ID',
    prop: 'productId',
    width: 75
  },
  {
    label: '名称',
    prop: 'name',
    // type: 'slot',
    minWidth: 300
  },
  {
    label: '类型',
    prop: 'type',
    type: 'dict'
  },
  {
    label: '负责人',
    prop: 'creatorName',
    width: '100px'
  },
  {
    label: '创建时间',
    prop: 'createTime',
    type: 'date',
    formatString: 'YYYY-MM-DD',
    width: '100px'
  },
  {
    label: '审核状态',
    prop: 'certificationStatus',
    type: 'dict',
    width: '120px'
  }
]

export const initSearchForm = () => {
  return {
    name: '',
    type: '',
    certificationStatus: ''
  }
}

const checkContactUsers = (label) => {
  return function (rule, value, callback) {
    if (!value.length) {
      callback(new Error(`${label}不能为空`))
    }
    callback()
  }
}

export const rules = {
  imageUrl: [{ required: true, message: '请上传图片', trigger: 'change' }],
  category: [{ required: true, message: '请选择类别', trigger: 'change' }],
  name: [
    { required: true, message: '请填写名称', trigger: 'blur' }
  ],
  onlineTime: [{ required: true, message: '请填写上线时间', trigger: 'blur' }],
  tagKeywords: [
    { type: 'array', min: 1, max: 5, message: '标签至少 1 个，最多 5 个', trigger: 'change' },
    { type: 'array', required: true, message: '请填写标签', trigger: 'change' }
  ],
  // attachs: [{ type: "array", required: true, message: "请上传附件", trigger: "blur" }],
  valuation: [{ required: true, message: '请填写估值', trigger: 'blur' }],
  instructions: [
    { required: true, message: '请填写估值说明', trigger: 'blur' }
  ],
  synopsis: [{ required: true, message: '请填写简介', trigger: 'blur' }],
  description: [{ required: true, message: '请填写详情', trigger: 'blur' }],
  userRelationCharges: [
    { required: true, validator: checkContactUsers('负责人'), trigger: 'blur' }
  ],
  attachs: [{
    required: true, message: '请上传附件', trigger: 'blur'
  }
  ]
}

export const ProductDTO = () => {
  return {
    id: 0,
    number: '',
    name: '',
    imageUrl: '',
    price: 0,
    synopsis: '',
    description: '',
    tagKeywords: [],
    previewImgUrl: [],
    createTime: '',
    updateTime: '',
    createBy: 0,
    updateBy: 0,
    orgId: 0,
    type: 1,
    certificationStatus: '',
    viewTimes: 0,
    sale: 0,
    submitTime: '',
    category: '',
    attach: '',
    publisherContact: '',
    orgContact: '',
    orgImg: '',
    orgName: '',
    creatorName: '',
    attachs: [],
    attachList: [],
    cash: 0,
    discountCash: 0,
    discountPrice: 0,
    attachName: '',
    isFree: '0',
    version: '',
    versionTime: '',
    detailsImg: '',
    isOfficial: '',
    isTop: '',
    topImage: '',
    topSort: 0,
    isRecommend: '',
    recommendImage: '',
    rank: '1',
    recommendSort: 0,
    score: 0,
    star: 0,
    collectionVolume: 0,
    collect: false,
    orgProductCount: 0,
    isBought: 0,
    isExempt: false,
    productList: [],
    planList: [],
    recommendProducts: [],
    orgProducts: [],
    productIds: [],
    customers: [],
    payCurrency: '',
    priceChecked: true,
    cashChecked: false
  }
}
